package com.xyzh05.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyzh05.dao.MaterialInfoDao;
import com.xyzh05.model.MaterialInfo;
import com.xyzh05.service.MaterialInfoManager;
import com.xyzh05.util.PageBean;

@Service("materialInfoManager")
@WebService(serviceName = "MaterialInfoService", endpointInterface = "com.xyzh05.service.MaterialInfoManager")
public class MaterialInfoManagerImpl extends
		GenericManagerImpl<MaterialInfo, Long> implements MaterialInfoManager {
	MaterialInfoDao materialInfoDao;

	@Autowired
	public MaterialInfoManagerImpl(MaterialInfoDao materialInfoDao) {
		super(materialInfoDao);
		this.materialInfoDao = materialInfoDao;
	}

	public PageBean findList(PageBean pageBean, MaterialInfo materialInfo) {
		StringBuilder sb = new StringBuilder();
		List list = new ArrayList();
		sb.append(" from MaterialInfo mi where 1 = 1 ");
		
		if(materialInfo.getMaterial().getVipService() != null){
			sb.append(" and mi.material.vipService.id = " + materialInfo.getMaterial().getVipService().getId());
		}

		if (pageBean != null) {
			if (pageBean.getSortCriterion() != null) {
				sb.append(" order by ");
				sb.append(pageBean.getSortCriterion() + " ");
				if (pageBean.getSortParamDirection() != null) {
					sb.append(pageBean.getSortParamDirection());
				}
			}
		}
		return materialInfoDao.getPageByHQL(sb.toString(), pageBean, list.toArray());
	}

}